package com.opc.client;

import com.opc.config.OpcClientConfigBean;
import com.opc.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

/**
 * https://blog.csdn.net/yhtppp/article/details/80680446
 *
 * @author SEG
 * @Classname OpcClientRunner
 * @Description TODO 同步数据时注释掉
 */
@Slf4j
@Component
@Order(value = 1)//这里表示启动顺序
public class OpcClientRunner implements CommandLineRunner {
    @Autowired
    private OpcClientBean opcClientBean;
    @Autowired
    private OpcClientConfigBean clientConfigBean;

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public void run(String... args) throws Exception {
        log.info("OpcClientRunner  starting ...........");
        //重置一下redis的key
//        List<Object> keyList = redisUtils.lRange("key_list", 0, -1);
//        for (Object o : keyList) {
//            redisUtils.hmSet(o.toString(), "val", 0);
//        }
        List<String> line = Arrays.asList("PVS1", "PVS6", "ROG7", "ROG8");
        for (String l : line) {
            redisUtils.set(l, 1);
        }
        opcClientBean.start(clientConfigBean.getIp(), clientConfigBean.getUser(), clientConfigBean.getPassword(), clientConfigBean.getDomain(), clientConfigBean.getClsid());
    }
}
